package cn.tedu._05mvcboot02.common.response;

import lombok.*;
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    //状态码,提示消息,具体数据
    private Integer state;
    private String message;
    private Object data;

    /*
    1.构造方法:针对于没有数据返回的控制器方法
 */
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    /*
        2.构造方法:针对于有具体数据返回的控制器方法
     */
    public JsonResult(StatusCode statusCode,Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult ok(){
        return ok(null);
    }
}
